<template>
  <el-dialog :close-on-click-modal="false" title="驳回" :visible="dialogVisible" @close="close" width="550px">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
      <el-form-item label="驳回原因：" :label-width="formLabelWidth" prop="opinion">
           <el-select class="w-100" v-model="ruleForm.opinion" placeholder = "请选择驳回原因">
                <el-option 
                    v-for="(item,index) in opinionList"
                    :key = "index"
                    :label = "item.dictDataName"
                    :value = "item.dictDataName">
                </el-option>
            </el-select>
      </el-form-item>
      <el-form-item label="快递编号：" :label-width="formLabelWidth" prop="ems">
        <el-input v-model="ruleForm.ems" placeholder="请输入快递编号" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { backPretrial,findByDictCode } from "../../config/api.js";
export default {
    name: "rejectDialog",
    data() {
        return {
            formLabelWidth: "90px",
            ruleForm: {
                opinion: "",
                ems: ""
            },
            opinionList:[],//驳回原因列表
            rules: {
                opinion: [
                    {
                        required: true,
                        message: "请输入驳回原因",
                        trigger: "change"
                    }
                ]
            }
        };
    },
    props: {
        record: Object, //数据
        dialogVisible: {
            type: Boolean,
            default: false
        }, //窗口显示/关闭
        onClose: Function //关闭弹窗的回调
    },
    mounted(){
        this.getOpinionList();
    },
    
    methods: {
         /**
         * 获取驳回原因列表
         */
        getOpinionList(){
            findByDictCode({dictCode:"backReason"}).then((result = {})=>{
                let data = result.data || [];
                this.opinionList = data;
            })
        },
        close(e) {
            this.$emit("onClose");
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid, values) => {
                if (valid) {
                  let {id,handleInfoName,handlePersonTelNo,handlePersonName} = this.record;
                    backPretrial({
                        id,
                        handleInfo:handleInfoName,
                        handlePersonName,
                        handlePersonTelNo,
                        ...this[formName]
                    }).then((res = {}) => {
                        this.$message({
                            message: "驳回成功",
                            type: "success"
                        });
                        this.$emit("callBack"); //getList
                    });
                } else {
                    return false;
                }
            });
        }
    },
    watch: {
        dialogVisible: function(val, oldVal) {
            if (val) {
                this.ruleForm = { opinion: "", ems: "" };
            }
        }
    }
};
</script>

